package comp.movel.ubiqua;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import comp.movel.ubiqua.ws.ConexaoWebService;

public class PassaOuRepassaActivity extends Activity {


	// Intent request codes
	public static final int REQUEST_CONNECT_DEVICE = 1;
	public static final int REQUEST_ENABLE_BT = 2;
	public static final int DISCOVERY_REQUEST = 0;

	private BluetoothAdapter mBluetoothAdapter = null;
	TextView numP;


	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		int qtd = ConexaoWebService.qtdPerguntas();
		setContentView(R.layout.menuprincipal);
		numP = (TextView) findViewById(R.id.numPerguntas);
		numP.setText(getResources().getString(R.string.totalPerguntas) + qtd);
		mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

	}

	public void jogar(View v) {
		if (!mBluetoothAdapter.isEnabled()) {
            Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
        // Otherwise, setup the chat session
        }else{
        	iniciarJogo();
        }
	}

	public void Sair(View v) {
		finish();
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		switch (resultCode) {
		case 0:
			Toast.makeText(getApplicationContext(), "Sem acesso a bluetooth", Toast.LENGTH_SHORT).show();
			break;
		case -1:
			iniciarJogo();
			break;

		default:
			break;
		}
		Log.e("request", ""+requestCode);
		Log.e("result", ""+resultCode);
	}

	private void iniciarJogo() {
		Intent i = new Intent(this, JogoActivity.class);
		startActivity(i);
	}
	
}